package com.xique.park.service.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xique.park.bean.domain.wechat.WxUser;
import com.xique.park.mapper.WxUserMapper;
import com.xique.park.service.service.IWxUserService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @program: xq-cloud
 * @ClassName WxUserServiceImpl
 * @description:
 * @author: HdongSun
 * @create: 2022-08-26 11:08
 **/
@Service
@Slf4j
@RequiredArgsConstructor
public class WxUserServiceImpl extends ServiceImpl<WxUserMapper, WxUser> implements IWxUserService {

    private final WxUserMapper wxUserMapper;

    @Override
    public List<WxUser> selectWxUserByUnionId(String unionId) {
        if (StrUtil.isEmpty(unionId)) {
            return null;
        }
        LambdaQueryWrapper<WxUser> condition = Wrappers.lambdaQuery();
        condition.eq(WxUser::getUnionId, unionId);
        List<WxUser> wxUsers = wxUserMapper.selectList(condition);
        if (wxUsers.size()>1){
            log.error("[停车小程序-微信登录]一个unionId存在多个wxUser，unionId：{}",unionId);
        }
        return wxUsers;
    }
}
